
package com.yunfei.api.product;

import com.yunfei.bo.TPersonalUserBo;
import com.yunfei.bo.product.ProductDetailBo;
import com.yunfei.bo.product.ProductPageBo;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.contants.UserCenterContants;
import com.yunfei.entity.TPersonalUserEntity;
import com.yunfei.enums.ResultStatus;
import com.yunfei.mapper.aiiidb.*;
import com.yunfei.utils.TokenUtil;
import com.yunfei.utils.string.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 产品详情页面接口
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@SuppressWarnings("ALL")
@Api(value = "产品详情页面",tags = "产品详情页面")
@RestController
@RequestMapping("/api/product/detail")
public class ProductDetailApiController {
    @Autowired
    private VideoMapper videoMapper;//产品路演视频
    @Autowired
    private ProductPageMapper productPageMapper;//产品详情
    @Autowired
    private ProductBeiAnMapper productBeiAnMapper;//产品备案信息
    @Autowired
    private ProductTagMapper productTagMapper;//产品标签
    @Autowired
    private ProductPingLunMapper productPingLunMapper; //产品评论
    @Autowired
    private ProductDetailMapper productDetailMapper; //产品详情
    @Autowired
    private ShiMingRenZhengForProductMapper shiMingRenZhengMapper; //实名认证
    @Autowired
    private TPersonalUserMapper tPersonalUserMapper;
    /**
    * @Description: 产品页面信息
    * @Author: zhengyunfei
    * @Date: 2019/1/11
    * @time:17:00
    */
    @GetMapping("/get")
    @ApiOperation(value = "产品详情页面",notes = "产品详情页面",position = 1,response = ProductDetailBo.class)
    @ResponseBody
    public Object get(String projId,String token){
        ResultModel resultModel=new ResultModel();
        Map<String,Object> resultMap=new HashMap<>();
        ProductDetailBo productDetailBo=null;//产品详细信息
        boolean isShiMingRenZhengFlg=false;//实名认证标识
        Map<String,Object> queryMap=new HashMap<>();
        queryMap.put("projId",projId);
        String videoUrl="";
        String mobile="";
        String userType="";
        String userId= TokenUtil.getInstance().getUserId(token);
        TPersonalUserEntity tPersonalUserEntity=tPersonalUserMapper.findById(userId);
        if(!StringUtil.isNullOrEmpty(tPersonalUserEntity)){
            mobile=tPersonalUserEntity.getMobile();
            userType=tPersonalUserEntity.getUserType();
        }
        //先判断当前登录的用户是个人还是理财师，如手机号码不为空，则为普通用户，否则为理财师
            //理财师

            productDetailBo= (ProductDetailBo) productDetailMapper.get(queryMap);

            ProductPageBo productPageBo= (ProductPageBo) productPageMapper.get(queryMap);
            if(!StringUtil.isNullOrEmpty(productPageBo)){
                productDetailBo.setPkId(projId);
                productDetailBo.setProductName(productPageBo.getProductName());
                productDetailBo.setDeadline(productPageBo.getDeadline());
                productDetailBo.setPerminBalance(productPageBo.getPerminBalance());
                if(StringUtil.isNullOrEmpty(productDetailBo.getYield())){
                    productDetailBo.setYield(productPageBo.getYield());
                }

            }
        if("01".equals(userType)){
            //普通客户
            //判断是否购买过产品
            Map<String,Object> mobileQueryMap=new HashMap<>();
            mobileQueryMap.put("mobile",mobile);
            mobileQueryMap.put("cFundCode",productDetailBo.getcFundCode());
            int isBuy=productPageMapper.getIsBuy(mobileQueryMap);
            productDetailBo.setIsBuy(isBuy);
        }
        resultMap.put("isShiMingRenZhengFlg",isShiMingRenZhengFlg);
        resultMap.put("productDetai",productDetailBo);
        resultModel.setCode(ResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        resultModel.setData(resultMap);
        return resultModel;
    }

}
